package io;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Mariano Zapata
 */
public abstract class Identificable implements Serializable {
    
    private List<Long> ruta;
    
    public Identificable(List<Long> ruta) {
        this.ruta= ruta;
    }
    
    public long obtenerId() {
        return ruta.get(ruta.size() - 1);
    }
    
    public List<Long> obtenerCopiaRuta()
    {
        List<Long> ret= new ArrayList<Long>();
        ret.addAll(ruta);
        return ret;
    }
    
    public boolean estaEnRuta(long id)
    {
        for (long l : ruta)
        {
            if (l == id)
                return true;
        }
        return false;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Identificable other = (Identificable) obj;
        if (this.obtenerId() != other.obtenerId()) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 41 * hash + (int) (this.obtenerId() ^ (this.obtenerId() >>> 32));
        return hash;
    }
}
